<template>
	<view style="width: 100vw;height: 100%;background-color: #ffffff;">
		<view style="width: 100%;height: 100%;overflow-y: scroll;">
			<view style="height: 5px;width: 100%;display: flex;align-items: center;">
			</view>
			<view style="height: 40px;width: 100%;display: flex;align-items: center;" v-for="(item,index) in novelList"
				@click="switchSectionClick(item,index)">
				<label v-if="item.isCurRead == true"
					style="font-size: 14px;color: red;margin-left: 10px;">{{item.cName}}</label>
				<label v-else style="font-size: 14px;color: #888;margin-left: 10px;">{{item.cName}}</label>
			</view>
		</view>

	</view>
</template>

<script>
	export default {

		data() {
			return {

				novelList: [{
						title: "序章 大乾王朝",
						id: 0,
						isCurRead: true,
					},
					{
						title: "第一章 令旗至兮风云起",
						id: 1,
						isCurRead: false,
					},
					{
						title: "第二章 不眠夜里陌生客",
						id: 2,
						isCurRead: false,
					}
				],

				// 书本Id
				bookCode: "",
				chapterIndex: 0,
				pageType: "",

			}
		},
		components: {

		},
		onLoad(options) {

			this.bookCode = options.bookCode;
			this.chapterIndex = options.chapterIndex;
			this.pageType = options.pageType;
			console.log(this.pageType, "---------");

		},

		created() {





		},
		mounted() {

			this.getChapterListDetail();

		},
		methods: {


			async getChapterListDetail() {

				var that = this
				var bookCode = this.bookCode

				try {
					var res = await this.$api.chapterList(bookCode);
					if (res.statusCode == 200) {
						this.novelList = res.data.data;
						this.novelList.map((item, index) => {

							if (index == (that.chapterIndex - 1)) {
								item.isCurRead = true
							} else {
								item.isCurRead = false
							}

						})
					} else {

					}

				} catch (error) {
					console.log(error)
				}

			},
			switchSectionClick(item, index) {



				let obj = {
					bookId: this.bookCode,
					chapter: index + 1, //章节的下标
					start: 0,
					currentPage: 0
				}


				//存储下当前看到当前小说的哪个章节
				uni.setStorageSync(this.bookCode, obj)

				if (this.pageType == "readDetail") {
					uni.$emit('switchSection', true);
					uni.navigateBack({});

				} else {
					uni.$emit('switchSectionDetail', true);
				}


			}

		},
	}
</script>

<style scoped lang="scss">
</style>